/**
 * 设计稿宽度
 */
export const DESIGN_WIDTH = 750;

export function getComponentElHeightRpx(self, el, callback) {
  const query = wx.createSelectorQuery().in(self)
  query.select(el).boundingClientRect(function (rect) {
    console.log(rect, 'getComponentElHeightRpx');
    const {
      height,
      width
    } = rect
    let ratio = DESIGN_WIDTH / width
    callback(height * ratio)
  }).exec()
}

//获取节点高度
export function getElHeightRpx(targetEl, callback) {
  wx.createSelectorQuery().select(targetEl).boundingClientRect(function (rect) {
    const {
      height,
      width
    } = rect
    let ratio = DESIGN_WIDTH / width
    callback(height * ratio)
  }).exec()
}

// 获取视口高度
export function getViewHeight(callback, unit = "rpx" || "px") {
  wx.getSystemInfo({
    success: (result) => {
      console.log(result, '=====result====');
      // 获取可使用窗口宽度
      let clientHeight = result.windowHeight;
      // 获取可使用窗口高度
      let clientWidth = result.windowWidth;
      // 算出比例
      let ratio = DESIGN_WIDTH / clientWidth;
      // 算出高度(单位rpx)
      let height = clientHeight * ratio;
      if (callback) {
        if (unit === 'px') {
          callback(clientHeight)
        } else {
          callback(height)
        }
      }

    },
  })
}
// 获取节点布局位置信息 boundingClientRect
export function getElClientRect(el, callback) {
  const query = wx.createSelectorQuery()
  query.select(el).boundingClientRect(function (res) {
    callback(res)
  }).exec()
}